package com.example.blog.model;

import com.example.blog.enums.ResultEnums;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Data
public class Result<T> {
    private int code;
    private String errorMSG;
    private T data;

    public static <T> Result success(T data){
        log.info("登录成功");
        Result result = new Result();
        result.setCode(ResultEnums.SUCCESS.getCode());
        result.setData(data);
        return result;
    }

    public static <T> Result noLogin(String errorMSG){
        log.info("登录失败");
        Result result = new Result();
        result.setCode(ResultEnums.NO_LOGIN.getCode());
        result.setErrorMSG(errorMSG);
        return result;
    }

    public static <T> Result noRegister(String errorMSG){
        log.info("注册失败");
        Result result = new Result();
        result.setCode(ResultEnums.NO_REGISTER.getCode());
        result.setErrorMSG(errorMSG);
        return result;
    }

    public static <T> Result fail(String errorMSG){
        log.info("其他错误");
        Result result =new Result();
        result.setCode(ResultEnums.FAIL.getCode());
        result.setErrorMSG(errorMSG);
        return result;
    }
    public static <T> Result fail(int code,String errorMSG){
        Result result =new Result();
        result.setCode(code);
        result.setErrorMSG(errorMSG);
        return result;
    }

}
